import uuid
from django.db import models
from django.urls import reverse
# Create your models here.

class TrendList(models.Model):
    id = models.CharField(max_length=128, primary_key=True, verbose_name='Id')
    user = models.ForeignKey('user.User', db_column='user', on_delete=models.CASCADE,
                             related_name='user', verbose_name='发送动态用户')
    rec_user = models.ForeignKey('user.User', null=True, db_column='rec_user', on_delete=models.CASCADE,
                                 related_name='rec_user', verbose_name='接收动态用户')
    content = models.TextField(verbose_name='动态内容')
    trend_time = models.DateTimeField(auto_now_add=True, verbose_name='发生时间')

    class Meta:
        managed = True
        db_table = 'trend_list'

    def save(self, *args, **kwargs):
        if not self.id:
            self.id = uuid.uuid4()
        if not self.rec_user:
            self.rec_user = self.user
        super(TrendList, self).save()